package demo;

//解决java里面没有多继承

interface IRunning{
    void running();
}

interface ISwimming{
    void swimming();
}

interface IFlying{
    void flying();
}

abstract class Animal{
    public String name;
    public int age;
    public String color;
    public void eat(){
        System.out.println();
    }

    public Animal(){
    }
    public Animal(String name,int age,String color){
        this.name = name;
        this.age = age;
        this.color = color;
    }
}

class Dog extends Animal implements IRunning,ISwimming{
    public Dog(){
    }

    public Dog(String name,int age,String color){
        super(name, age, color);
    }

    @Override
    public void running() {
        System.out.println(name + "正在奔跑");
    }

    @Override
    public void swimming() {
        System.out.println(name + "正在狗刨");
    }

    @Override
    public void eat() {
        System.out.println(name + "正在吃狗粮");
    }
}

class Duck extends Animal implements ISwimming,IFlying,IRunning{

    public Duck(){

    }
    public Duck(String name,int age,String color){
        super(name,age,color);
    }
    @Override
    public void swimming() {
        System.out.println(name + "正在游泳");
    }

    @Override
    public void flying() {
        System.out.println(name + "正在短暂飞");
    }

    @Override
    public void running() {
        System.out.println(name + "正在跑");
    }

    @Override
    public void eat() {
        System.out.println(name + "正在吃鸭粮");
    }
}

public class Test2 {
    //向下转型
//    public static void run(Animal animal){
//        if(animal instanceof Dog) {
//            Dog dog = (Dog) animal;
//            dog.running();
//        }
//    }

    //只有具备这个功能就能使用
    public static void run(IRunning iRunning){
        iRunning.running();
    }

    //前提必须是动物才能使用
    public static void eat(Animal animal){
        animal.eat();
    }
    public static void main(String[] args) {
        Dog dog = new Dog("black",10,"blue");
        Duck duck = new Duck("bule",5,"black");
        run(dog);
        run(duck);
        System.out.println("=====================");
        eat(dog);
        eat(duck);
    }
}
